from abc import ABCMeta, abstractmethod

from ..container import ComponentContainer


class AbstractLossEvaluator(metaclass=ABCMeta):

    def __call__(self, container: ComponentContainer):
        criteria = container.criteria
        data = container.data
        pred = container.pred

        container.loss = self.evaluate(data, pred, criteria)

    @abstractmethod
    def evaluate(self, data, pred, criteria):
        pass


class ClsLossEvaluator(AbstractLossEvaluator):

    def evaluate(self, data, pred, criteria):
        _, label = data
        return criteria(pred, label)
